package com.common.utils;

import lombok.Data;
import org.apache.http.HttpStatus;

import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 菠萝头
 * @Email: 1069881480@qq.com
 * @Date: 2022/07/03/12:41
 * @Description:
 */
@Data
public class R extends HashMap<String,Object> {
    public R() {
        put("code",0);
        put("mas","成功");
    }

    public static R error(int code,String msg){
        R r = new R();
        r.put("code",code);
        r.put("msg",msg);
        return r;

    }
    public static R error(){
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR,"出现异常");
    }
    public static R error(String msg){
        return error(500,msg);
    }

    public static R ok(){
        return new R();
    }
    public static R ok(int code,String msg){
        R r = new R();
        r.put("code",code);
        r.put("msg",msg);
        return r;
    }
    public static R ok(String msg){
        R r = new R();
        r.put("code",0);
        r.put("msg",msg);
        return r;
    }

//    返回R类型而不是Object
    @Override
    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }

}
